package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.StbCompany;
import com.ruoyi.system.domain.StbHonour;
import com.ruoyi.system.service.IStbCompanyService;
import com.ruoyi.system.service.IStbHonourService;

/**
 * 荣誉Controller
 * 
 * @author ruoyi
 * @date 2020-02-08
 */
@Controller
@RequestMapping("/system/honour")
public class StbHonourController extends BaseController
{
    private String prefix = "system/honour";

    @Autowired
    private IStbHonourService stbHonourService;
    
    @Autowired
	private IStbCompanyService stbCompanyService;


    

    @RequiresPermissions("system:honour:view")
    @GetMapping()
    public String honour(ModelMap mmap)
    {
    	StbCompany stbCompany = new  StbCompany();
    	List<StbCompany> list = stbCompanyService.selectStbCompanyList(stbCompany);
    	mmap.put("companyList",list);
        return prefix + "/honour";
    }
    
    /*
	 * 查询企业荣誉  企业名称 compname:产品名称 honourname:荣誉内容 honourdetail
	 */
    @PostMapping("/comphonour")
    @ResponseBody
    public List<Map<String,Object>> selectCompHonour(){
    	StbHonour stbHonour = new StbHonour();
    	List<Map<String, Object>> comphonourList = stbHonourService.selectCompHonour(stbHonour);
    	return comphonourList;
    }

    /**
     * 查询荣誉列表
     */
    @RequiresPermissions("system:honour:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StbHonour stbHonour)
    {
        startPage();
        List<StbHonour> list = stbHonourService.selectStbHonourList(stbHonour);
        return getDataTable(list);
    }

    /**
     * 导出荣誉列表
     */
    @RequiresPermissions("system:honour:export")
    @Log(title = "荣誉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StbHonour stbHonour)
    {
        List<StbHonour> list = stbHonourService.selectStbHonourList(stbHonour);
        ExcelUtil<StbHonour> util = new ExcelUtil<StbHonour>(StbHonour.class);
        return util.exportExcel(list, "honour");
    }

    /**
     * 新增荣誉
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	StbCompany stbCompany = new  StbCompany();
    	List<StbCompany> list = stbCompanyService.selectStbCompanyList(stbCompany);
    	mmap.put("companyList",list);
        return prefix + "/add";
    }

    /**
     * 新增保存荣誉
     */
    @RequiresPermissions("system:honour:add")
    @Log(title = "荣誉", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StbHonour stbHonour)
    {
    	stbHonour.setCreateBy(ShiroUtils.getLoginName());
    	stbHonour.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(stbHonourService.insertStbHonour(stbHonour));
    }
    

    /**
     * 修改荣誉
     */
    @GetMapping("/edit/{honourId}")
    public String edit(@PathVariable("honourId") Long honourId, ModelMap mmap)
    {
    	StbCompany stbCompany = new  StbCompany();
    	List<StbCompany> list = stbCompanyService.selectStbCompanyList(stbCompany);
    	mmap.put("companyList",list);
        StbHonour stbHonour = stbHonourService.selectStbHonourById(honourId);
        mmap.put("stbHonour", stbHonour);
        return prefix + "/edit";
    }

    /**
     * 修改保存荣誉
     */
    @RequiresPermissions("system:honour:edit")
    @Log(title = "荣誉", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StbHonour stbHonour)
    {
    	stbHonour.setCreateBy(ShiroUtils.getLoginName());
    	stbHonour.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(stbHonourService.updateStbHonour(stbHonour));
    }

    /**
     * 删除荣誉
     */
    @RequiresPermissions("system:honour:remove")
    @Log(title = "荣誉", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stbHonourService.deleteStbHonourByIds(ids));
    }
}
